package com.chengfei.thread.demo1;

/**
 * @author chengfei5
 * @date 2019/1/3
 */
public class NewThread1 extends Thread{
    public NewThread1(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (!interrupted()){
            System.out.println(getName()+"创建新线程执行了！");
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        NewThread1 thread1 = new NewThread1("first");
        NewThread1 thread2 = new NewThread1("second");

        thread1.start();
        thread2.start();

        thread1.interrupt();
        //不建议使用的原因是因为只是让该线程进入无限期等待，而它所持有的锁资源都没有被释放
//        thread1.stop();
    }
}
